package org.smartcti.freeswitch.inbound.internal;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;



public  class BuilderUtils {
	private  final String delimiter = ":";
	private  final Logger logger = LogManager.getLogger(BuilderUtils.class);
	
	
	
	static class SingletonHolder {
		static BuilderUtils instance = new BuilderUtils();
	}
	
	public static BuilderUtils getInstance() {
		return SingletonHolder.instance;
	}

	
	
	
	private BuilderUtils() {
		super();
		try {
			 
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
		}
		
		
	}
	




	public  Map<String, String> buildMap(final String  eventString)
    {
        if (eventString == null)
        {
            return null;
        }
        final String[] lines = StringUtils.split(eventString, "\n");
        final Map<String, String> map = new LinkedHashMap<String, String>();
        for (String line : lines)
        {
            final String key = StringUtils.substringBefore(line,delimiter);
        	final String value = StringUtils.substringAfter(line,delimiter);
            if(key!=null && value!=null){
            	map.put(key.trim(), value.trim());
            }else{
            	logger.warn("Malformed line '" + line + "' for a map property");
            	
            }
        }
        return map;
    }
	
	
	public void setAttributes(Object target, Map<String, String> attributes){
		for(final Map.Entry<String, String> entry:attributes.entrySet()){
			entry.getKey();
			
		}
		  
	}

}
